from flask import Flask
import pandas as pd
from itertools import combinations
app= Flask(__name__)

frequent_itemsets =pd.read_pickle('./frequent_itemsets.pkl')
rules =pd.read_pickle('./rules.pkl')
@app.route("/recommend",methods=['POST'])
def recommend():

  data=request.json.get('items',[])

recommendDations = []
for idx, rule in rules.iterrows():
    antecedents = list(rule['antecedents'])
    consequents = list(rule['consequents'])

    if set(antecedents).issubset(set(data)):
       recommendDations.extend(consequents)

       recommendDations = list(set(recommendDation) - set(data))
       return jsonify({"recommendDations": recommendDations})

if __name__ == "__main__":
 app.run()

